load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("//pkg/testutils:buildutil/buildutil.bzl", "disallowed_imports_test")

go_library(
    name = "roachpb",
    srcs = [
        "data.go",
        "index_usage_stats.go",
        "internal.go",
        "leaseinfo.go",
        "merge_spans.go",
        "metadata.go",
        "metadata_replicas.go",
        "span_config.go",
        "span_group.go",
        "tenant.go",
        "version.go",
    ],
    embed = [":roachpb_go_proto"],
    importpath = "github.com/cockroachdb/cockroach/pkg/roachpb",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/base/serverident",
        "//pkg/geo/geopb",
        "//pkg/keysbase",
        "//pkg/kv/kvserver/allocator/load",
        "//pkg/kv/kvserver/concurrency/isolation",
        "//pkg/kv/kvserver/concurrency/lock",
        "//pkg/raft/raftpb",
        "//pkg/storage/enginepb",
        "//pkg/util",
        "//pkg/util/admission/admissionpb",
        "//pkg/util/bitarray",
        "//pkg/util/buildutil",
        "//pkg/util/duration",
        "//pkg/util/encoding",
        "//pkg/util/hlc",
        "//pkg/util/humanizeutil",
        "//pkg/util/interval",
        "//pkg/util/log",
        "//pkg/util/protoutil",
        "//pkg/util/syncutil",
        "//pkg/util/timetz",
        "//pkg/util/uuid",
        "@com_github_cockroachdb_apd_v3//:apd",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_cockroachdb_redact//:redact",
        "@com_github_golang_mock//gomock",  # keep
        "@org_golang_google_grpc//metadata",  # keep
    ],
)

go_test(
    name = "roachpb_test",
    size = "small",
    srcs = [
        "data_test.go",
        "index_usage_stats_test.go",
        "main_test.go",
        "merge_spans_test.go",
        "metadata_replicas_test.go",
        "metadata_test.go",
        "span_config_conformance_report_test.go",
        "span_config_test.go",
        "span_group_test.go",
        "string_test.go",
        "tenant_test.go",
        "version_test.go",
    ],
    embed = [":roachpb"],
    deps = [
        "//pkg/cli/exit",
        "//pkg/keys",
        "//pkg/kv/kvserver/concurrency/isolation",
        "//pkg/kv/kvserver/concurrency/lock",
        "//pkg/raft",
        "//pkg/raft/confchange",
        "//pkg/raft/quorum",
        "//pkg/raft/raftpb",
        "//pkg/raft/tracker",
        "//pkg/storage/enginepb",
        "//pkg/testutils/zerofields",
        "//pkg/util",
        "//pkg/util/bitarray",
        "//pkg/util/duration",
        "//pkg/util/encoding",
        "//pkg/util/hlc",
        "//pkg/util/leaktest",
        "//pkg/util/log",
        "//pkg/util/protoutil",
        "//pkg/util/randutil",
        "//pkg/util/timeutil",
        "//pkg/util/uuid",
        "@com_github_cockroachdb_apd_v3//:apd",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_cockroachdb_redact//:redact",
        "@com_github_kr_pretty//:pretty",
        "@com_github_stretchr_testify//assert",
        "@com_github_stretchr_testify//require",
    ],
)

proto_library(
    name = "roachpb_proto",
    srcs = [
        "data.proto",
        "index_usage_stats.proto",
        "internal.proto",
        "io-formats.proto",
        "metadata.proto",
        "span_config.proto",
        "span_stats.proto",
    ],
    strip_import_prefix = "/pkg",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/kv/kvserver/concurrency/lock:lock_proto",
        "//pkg/kv/kvserver/readsummary/rspb:rspb_proto",
        "//pkg/storage/enginepb:enginepb_proto",
        "//pkg/util:util_proto",
        "//pkg/util/admission/admissionpb:admissionpb_proto",
        "//pkg/util/hlc:hlc_proto",
        "@com_github_cockroachdb_errors//errorspb:errorspb_proto",
        "@com_github_gogo_protobuf//gogoproto:gogo_proto",
        "@com_google_protobuf//:duration_proto",
        "@com_google_protobuf//:timestamp_proto",
        "@go_googleapis//google/api:annotations_proto",
    ],
)

go_proto_library(
    name = "roachpb_go_proto",
    compilers = ["//pkg/cmd/protoc-gen-gogoroach:protoc-gen-gogoroach_compiler"],
    importpath = "github.com/cockroachdb/cockroach/pkg/roachpb",
    proto = ":roachpb_proto",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/kv/kvserver/concurrency/lock",
        "//pkg/kv/kvserver/readsummary/rspb",
        "//pkg/storage/enginepb",
        "//pkg/util",
        "//pkg/util/admission/admissionpb",
        "//pkg/util/hlc",
        "@com_github_cockroachdb_errors//errorspb",
        "@com_github_gogo_protobuf//gogoproto",
        "@org_golang_google_genproto//googleapis/api/annotations:go_default_library",
    ],
)

disallowed_imports_test(
    "roachpb",
    disallow_cdeps = True,
)
